package cn.dc406.labc406mgr.controller;


import cn.dc406.labc406mgr.entity.Users;
import cn.dc406.labc406mgr.mapper.UsersWapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class UsersController {

    @Autowired(required = false)//注入相应对的内容
    UsersWapper usersWapper;

    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/selectAllUser")
    public List<Users> selectAllUser()
    {
        return usersWapper.selectAllUser();
    }

    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/selectUserbyUsername")
    public List<Users> selectUserbyUsername(String username)
    {
        return usersWapper.selectUserbyUsername(username);
    }
    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/updatebyUsername")
    Boolean updatebyUsername(@RequestBody Users users)
    {
        System.out.println(users);
        return usersWapper.updatebyUsername(users);
    }

    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/deletebyUsername")
    Boolean deletebyUsername(String username)
    {
        return usersWapper.deleteItem(username);
    }

    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/addUser")
    Boolean addUser(@RequestBody Users user)
    {
        System.out.println(user);
        return usersWapper.addUser(user);
    }
}
